<template>
    <view class="app">
        <load :ready="ready"></load>
		<view class="fixed-head">
			<u-tabs :list="navlist" active-color="#497CD0" :is-scroll="false" :current="current" @change="change"></u-tabs>
			
		</view>
		
		<u-gap height="80"></u-gap>
		
		<view class="order-list">
			<view class="order-item" v-for="(item ,index) in list" :key="item.id">
				<view class="order-head">
					<text class="num">关联订单号：{{item.orderSn}}</text>
					<view class="state">
						<u-tag text="待审核" v-if="item.status == 0" mode="dark" color="#497CD0" bg-color="#EDF3FF" border-color="#ECECEC"/>
							<u-tag text="审核失败" v-if="item.status == 1"  mode="dark" color="#FF4747" bg-color="#FFEDED" border-color="#FFEDED" />
						<u-tag text="待开票" v-if="item.status == 2"  mode="dark" color="#333" bg-color="#ECECEC" 待开票="#ECECEC"/>
						<u-tag text="已开票" v-if="item.status == 3" mode="dark" color="#5AB5A4" bg-color="#f7ffff" border-color="#f7ffff"/>
					</view>
				</view>
				
				<view class="desc-info">
					<view class="text">发票类型：{{item.invoiceTypeName}}</view>
					<view class="text">开票类型：{{item.billingTypeName}}</view>
					<view class="text">姓名：{{item.name}}</view>
				</view>
				
				<view class="order-foot">
					<view class="left">
						申请日期：{{item.createTime}}
					</view>
					<view class="btnbox">
						<u-button class="btn" type="primary" @click="link(`/pages/user/invoice_info?id=${item.id}`)" :custom-style="btnStyle" size="medium">查看</u-button>
					</view>
				</view>
			</view>
			
			
			<list-tip :notData="listTip.notData" :isPage="listTip.isPage" :isLoading="listTip.isLoading">
			    <u-empty slot="notdata" text="暂无数据"  margin-top="100"></u-empty>
			</list-tip>
		
		</view>
    </view>
</template>

<script>
import { mapState, mapActions, mapMutations, mapGetters } from 'vuex';
import { mixinsBase } from '@/common/js/mixins';
let that;
export default {
    mixins: [mixinsBase],
    components: {},
    data() {
        return {
            // ready: true,
			navlist:[{
				name:'全部',
			},{
				name:'待审核',
				status:0,
			},{
				name:'待开票	',
				status:2,
			},{
				name:'已开票',
				status:3,
			},],
			
			current: 0,
			btnStyle:{
				background: '#497CD0',
				borderRadius: '16px',
				padding:'0 15px',
			},
			listTip: {},
			list:[],
        };
    },
    onLoad() {
        that = this;
    },
    onReady() {
    },
    onShow() {
		this.$list.init(this);
		this.getList();
    },
    onUnload() {
        that = null;
    },
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {
        // this.getInit(data=>{
        //      uni.stopPullDownRefresh();
        //      common.showTip('刷新成功');
        // });
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {
		this.$list.onReachBottom(this)
	},

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {
        //       return {
        // 	// path,
        // 	imageUrl:config.shareImg,
        // 	// title
        // }
    },
    methods: {
		change(e){
			console.log(e);
			this.current = e;
			this.$list.init(this);
			this.getList();
		},
		async getList() {
		    let listTip = this.listTip;
		    let res = {};
		    let params = {
		        pageNum: listTip.p,
		        pageSize: listTip.size,
		    };
			if(this.current>0){
				params.status = this.navlist[this.current].status
			}
		    try {
		        res = await this.$api.invoiceList(params);
		    } catch (e) {
		        uni.hideLoading();
		        console.log('err', e);
		    }
		    if (res.data.code == this.$config.RESOK) {
		        let list = res.data.rows || [];
		        let setdata = this.$list.normalData(list, this);
				console.log(setdata);
		        this.list = setdata.list;
		        this.listTip = setdata.listTip;
		        if (setdata.list.length >= res.data.total && listTip.p > 1 || !list.length) {
		            this.$list.notdata(this);
		        } 
		    } 
		},
        ...mapActions([])
    },
    computed: {
        ...mapState({
            userInfo: 'userInfo'
        })
    }
};
</script>

<style scoped lang="scss">
page {
    background-color: $uni-bg-color-grey;
}

.tab-wrap{
	display: flex;
	width: 100%;
	text-align: center;
	height: 90rpx;
	line-height: 90rpx;
	border-bottom: 2px solid #eee;
	.tab-item{
		width: 50%;
		font-size: 16px;
		&.active{
			border-bottom: 4px solid $color;
			color: $color;
		}
	}
}
.fixed-head{
	padding: 0 30rpx;
	background: #fff;
	position: fixed;
	left: 0;
	width: 100%;
	z-index: 99;
}
.order-list{
	padding: 20rpx 30rpx;
	.order-item{
		background: #fff;
		margin-bottom: 20rpx;
		border-radius: 12px;
		padding: 0 30rpx;
	}
	.order-head{
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 5px 0;
	}
	
	.order-foot{
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 20rpx 0;
		.left{
			color: #818181;
		}
	}
}

.desc-info{
	padding: 20rpx 0;
	border-top: 1px solid #F4F4F4;
	border-bottom: 1px solid #F4F4F4;
	.text{
		padding: 3px 0;
		font-size: 13px;
		color: #666;
	}
}
</style>
